Power of Two

Given an integer, write a function to determine if it is a power of two.

Solution:

  1. public class Solution {
  2. public boolean isPowerOfTwo(int n) {
  3. return (n > 0 && (n & (n - 1)) == 0);
  4. }
  5. }